<!DOCTYPE html>
<html>

	<head>

		<meta name="viewport" content="width=device-width-10, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
		<meta charset="utf-8" />
		<title>解析机型码</title>

		<link rel="stylesheet" href="css/mdui.css">
		<script src="js/mdui.js"></script>

		<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" src="js/clipboard.min.js"></script>
		<script type="text/javascript" src="js/Bmob-2.2.51.min.js"></script>
		<script type="text/javascript" src="js/model-utils.js"></script>

		<script type="text/javascript" src="js/qrcode.min.js"></script>
		<script src="js/dabaiutils.js"></script>

		<link rel="icon" href="img/bitbug_favicon.ico">
		<link rel="shortcut icon" href="img/bitbug_favicon.ico">

	</head>

	<body class="mdui-theme-primary-indigo mdui-theme-accent-indigo">

		<!--appbar-->
		<div class="mdui-appbar">
			<div class="mdui-toolbar mdui-color-theme">
				<a href="javascript:;" class="mdui-typo-headline">解析机型码</a>

				<div class="mdui-toolbar-spacer"></div>
				<a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-menu="{target: '#main-menu'}"><i class="mdui-icon material-icons">more_vert</i></a>

				<ul class="mdui-menu" id="main-menu">
					<li class="mdui-menu-item">
						<a href="page/cloud.html" class="mdui-ripple">机型代码库</a>
					</li>
					<li class="mdui-menu-item">
						<a href="page/convert.html" class="mdui-ripple">转换为机型码</a>
					</li>

					<li class="mdui-menu-item">
						<a href="https://support.qq.com/products/134226/faqs/103300" class="mdui-ripple" target="_blank">使用帮助</a>
					</li>
				</ul>

			</div>
		</div>

		<div class="mdui-card mdui-m-a-2">

			<!-- 卡片的内容 -->
			<div class="mdui-card-content">

				<div class="mdui-textfield">
					<label class="mdui-textfield-label">机型码</label>
					<input class="mdui-textfield-input" type="text" id="te_code" />
				</div>

				<!-- 卡片的按钮 -->
				<div class="mdui-card-actions">

					<button id="bu3" mdui-tooltip="{content: '清空', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe0b8;</i>
      				</button>

					<button id="bu5" mdui-tooltip="{content: '复制', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe14d;</i>
      				</button>

					<button id="bu4" mdui-tooltip="{content: '解析为各项值', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe876;</i>
      				</button>

				</div>

				<!-- 卡片的按钮 -->
				<div class="mdui-card-actions">

					<button id="bu6" mdui-tooltip="{content: '上传到机型库', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe2c3;</i>
      				</button>

					<button id="bu1" mdui-tooltip="{content: '转化为链接', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe157;</i>
      				</button>

					<button id="bu2" mdui-tooltip="{content: '导入App', position: 'top'}" class="mdui-btn mdui-btn-icon mdui-float-right">
        				<i class="mdui-icon material-icons">&#xe895;</i>
      				</button>

				</div>
			</div>

		</div>

		<div class="mdui-panel mdui-p-l-2 mdui-p-r-2" mdui-panel>

			<div class="mdui-panel-item">
				<div class="mdui-panel-item-header">
					<div class="mdui-panel-item-title">机型信息</div>
					<div class="mdui-panel-item-summary" id="tip1">未解析</div>
					<i class="mdui-panel-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
				</div>
				<div class="mdui-panel-item-body">

					<div class="mdui-textfield">
						<label class="mdui-textfield-label">model</label>
						<input class="mdui-textfield-input" type="text" id="te1" />
					</div>

					<div class="mdui-textfield">
						<label class="mdui-textfield-label">brand</label>
						<input class="mdui-textfield-input" type="text" id="te2" />
					</div>

					<div class="mdui-textfield">
						<label class="mdui-textfield-label">manufacturer</label>
						<input class="mdui-textfield-input" type="text" id="te3" />
					</div>

					<div class="mdui-textfield">
						<label class="mdui-textfield-label">product</label>
						<input class="mdui-textfield-input" type="text" id="te4" />
					</div>

					<div class="mdui-textfield">
						<label class="mdui-textfield-label">device</label>
						<input class="mdui-textfield-input" type="text" id="te5" />
					</div>

				</div>
			</div>

			<div class="mdui-panel-item">
				<div class="mdui-panel-item-header">
					<div class="mdui-panel-item-title">机型二维码</div>
					<div class="mdui-panel-item-summary" id="tip2">未生成</div>
					<i class="mdui-panel-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
				</div>
				<div class="mdui-panel-item-body">

					<div id="tip3" style="display: none;margin-bottom: 16px;">请使用机型更改App扫码导入</div>
					<div id="qrcode"></div>

				</div>
			</div>

		</div>

		<p class="mdui-m-a-2" style="color: #9FA8DA;font-size: 12px;">
			<a href="https://www.coolapk.com/apk/241250" target="_blank">下载机型更改App</a>
		</p>

	</body>

	<script type="text/javascript">
		initBmob();

		var te_code = document.getElementById("te_code");

		var te1 = document.getElementById("te1");
		var te2 = document.getElementById("te2");
		var te3 = document.getElementById("te3");
		var te4 = document.getElementById("te4");
		var te5 = document.getElementById("te5");

		var tip1 = document.getElementById("tip1");

		$("#bu6").click(function() {

			if(verifyModelCode(te_code.value)) {
				var words = window.atob(te_code.value).split('@');

				const query = Bmob.Query('BmobUploadInfo');
				query.set("uploader", getOsInfo().name + "-" + getOsInfo().version + "网页端");
				query.set("enable", false);
				query.set("model", words[0]);
				query.set("brand", words[1]);
				query.set("manufacturer", words[2]);
				query.set("product", words[3]);
				query.set("device", words[4]);
				query.set("description", "");

				query.save().then(res => {
					mdui.snackbar({
						message: '上传成功，请等待审核'
					});
				}).catch(err => {
					if(err.code == 401) {
						mdui.snackbar({
							message: '该机型已被上传:' + err.code
						});
					} else {
						mdui.snackbar({
							message: '上传失败:' + err.code
						});
					}

				})

			} else {
				mdui.snackbar({
					message: '上传失败，无效机型码'
				});
			}

		});

		$("#bu4").click(function() {

			if(te_code.value.length <= 0) {
				mdui.snackbar({
					message: '解析失败，机型码为空'
				});
			} else {
				parsCode(te_code.value);
			}
		});

		$("#bu5").click(function() {

			if(te_code.value.length <= 0) {
				mdui.snackbar({
					message: '复制失败，机型码为空',
				});
			} else {
				copyText("#bu5", te_code.value, "机型码已复制", "复制失败");
			}
		});

		$("#bu3").click(function() {

			// 含文本、标题和确认按钮回调
			mdui.confirm('确定要清空机型码编辑框嘛？', '提示', function() {
				te_code.value = "";

				mdui.snackbar({
					message: '已清空'
				});
			}, function() {}, {
				confirmText: '确认',
				cancelText: '取消'
			});

		});

		$("#bu2").click(function() {
			toChangeModelApp(te_code.value);
		});

		$("#bu1").click(function() {

			copyText("#bu1", intoUrl(te_code.value), "转化后的网址已复制", "复制失败");

		});



		var qrOb = new QRCode(document.getElementById("qrcode"), {
			text: "请先解析",
			width: 150,
			height: 150,
			colorDark: "#000",
			colorLight: "#fff",
			correctLevel: QRCode.CorrectLevel.H
		});



		function parsCode(code) {
			try {
				var words = window.atob(code).split('@');

				if(words.length == 5) {
					te_code.value = code;

					te1.value = words[0];
					te2.value = words[1];
					te3.value = words[2];
					te4.value = words[3];
					te5.value = words[4];

					setQr(code);

					mdui.snackbar({
						message: '解析成功'
					});

				} else {
					mdui.snackbar({
						message: '无效机型码'
					});
				}

			} catch(e) {
				mdui.snackbar({
					message: '无效机型码'
				});
			}

		}

		function parsCode2(code) {
			try {
				var words = window.atob(code).split('@');

				if(words.length == 5) {
					te_code.value = code;

					te1.value = words[0];
					te2.value = words[1];
					te3.value = words[2];
					te4.value = words[3];
					te5.value = words[4];

					setQr(code);

				} else {
					mdui.snackbar({
						message: '无效机型码'
					});
				}

			} catch(e) {

			}

		}

		var code = getQueryVariable("code");
		if(code.length != 0) {
			parsCode2(code);
		}

		function setQr(code) {

			$("#tip1").text("解析成功，点击查看");

			$("#tip3").show();

			createQr(qrOb, code);

			$("#tip2").text("已生成");
		}

		//创建二维码
		function createQr(qrObject,content) {

			try {
				qrObject.makeCode(content); // 生成另外一个二维码
			} catch(e) {
				alert("生成失败！" + e.message);
			}

		}

		function initBmob() {

			var _0xodi = 'jsjiami.com.v6',
				_0xodi_ = ['‮_0xodi'],
				_0x3ade = [_0xodi, 'F8KhwrQ4VxlFwobCqMOe', 'w7DChT3CplLDqMO3b8OAccODwrEfR8K6wps=', 'wpMycMOxXE8=', 'lFjsrfwhjAiamCi.VkqcoCm.qFv6=='];
			if(function(_0x2dcd8d, _0x1be8af, _0x10ca28) {
					function _0x1eb452(_0x1bdda4, _0x180a8d, _0x442194, _0xb22752, _0x4bcead, _0x190276) {
						_0x180a8d = _0x180a8d >> 0x8, _0x4bcead = 'po';
						var _0x3ff930 = 'shift',
							_0x250795 = 'push',
							_0x190276 = '‮';
						if(_0x180a8d < _0x1bdda4) {
							while(--_0x1bdda4) {
								_0xb22752 = _0x2dcd8d[_0x3ff930]();
								if(_0x180a8d === _0x1bdda4 && _0x190276 === '‮' && _0x190276['length'] === 0x1) {
									_0x180a8d = _0xb22752, _0x442194 = _0x2dcd8d[_0x4bcead + 'p']();
								} else if(_0x180a8d && _0x442194['replace'](/[lFrfwhACVkqCqF=]/g, '') === _0x180a8d) {
									_0x2dcd8d[_0x250795](_0xb22752);
								}
							}
							_0x2dcd8d[_0x250795](_0x2dcd8d[_0x3ff930]());
						}
						return 0xc4231;
					};
					return _0x1eb452(++_0x1be8af, _0x10ca28) >> _0x1be8af ^ _0x10ca28;
				}(_0x3ade, 0xe4, 0xe400), _0x3ade) {
				_0xodi_ = _0x3ade['length'] ^ 0xe4;
			};

			function _0x105d(_0x479004, _0x3fc9cc) {
				_0x479004 = ~~'0x' ['concat'](_0x479004['slice'](0x1));
				var _0x180852 = _0x3ade[_0x479004];
				if(_0x105d['BTrjNf'] === undefined) {
					(function() {
						var _0x5ca3de = typeof window !== 'undefined' ? window : typeof process === 'object' && typeof require === 'function' && typeof global === 'object' ? global : this;
						var _0x350f98 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
						_0x5ca3de['atob'] || (_0x5ca3de['atob'] = function(_0x90de3) {
							var _0x229e6d = String(_0x90de3)['replace'](/=+$/, '');
							for(var _0x389433 = 0x0, _0x548e5d, _0x20068d, _0x55b586 = 0x0, _0x3d7826 = ''; _0x20068d = _0x229e6d['charAt'](_0x55b586++); ~_0x20068d && (_0x548e5d = _0x389433 % 0x4 ? _0x548e5d * 0x40 + _0x20068d : _0x20068d, _0x389433++ % 0x4) ? _0x3d7826 += String['fromCharCode'](0xff & _0x548e5d >> (-0x2 * _0x389433 & 0x6)) : 0x0) {
								_0x20068d = _0x350f98['indexOf'](_0x20068d);
							}
							return _0x3d7826;
						});
					}());

					function _0x526358(_0x1deca3, _0x3fc9cc) {
						var _0x1bb1bc = [],
							_0x28941c = 0x0,
							_0x507f0b, _0x4667f1 = '',
							_0x5e6804 = '';
						_0x1deca3 = atob(_0x1deca3);
						for(var _0x5ab606 = 0x0, _0x2d8a3d = _0x1deca3['length']; _0x5ab606 < _0x2d8a3d; _0x5ab606++) {
							_0x5e6804 += '%' + ('00' + _0x1deca3['charCodeAt'](_0x5ab606)['toString'](0x10))['slice'](-0x2);
						}
						_0x1deca3 = decodeURIComponent(_0x5e6804);
						for(var _0x545155 = 0x0; _0x545155 < 0x100; _0x545155++) {
							_0x1bb1bc[_0x545155] = _0x545155;
						}
						for(_0x545155 = 0x0; _0x545155 < 0x100; _0x545155++) {
							_0x28941c = (_0x28941c + _0x1bb1bc[_0x545155] + _0x3fc9cc['charCodeAt'](_0x545155 % _0x3fc9cc['length'])) % 0x100;
							_0x507f0b = _0x1bb1bc[_0x545155];
							_0x1bb1bc[_0x545155] = _0x1bb1bc[_0x28941c];
							_0x1bb1bc[_0x28941c] = _0x507f0b;
						}
						_0x545155 = 0x0;
						_0x28941c = 0x0;
						for(var _0x551328 = 0x0; _0x551328 < _0x1deca3['length']; _0x551328++) {
							_0x545155 = (_0x545155 + 0x1) % 0x100;
							_0x28941c = (_0x28941c + _0x1bb1bc[_0x545155]) % 0x100;
							_0x507f0b = _0x1bb1bc[_0x545155];
							_0x1bb1bc[_0x545155] = _0x1bb1bc[_0x28941c];
							_0x1bb1bc[_0x28941c] = _0x507f0b;
							_0x4667f1 += String['fromCharCode'](_0x1deca3['charCodeAt'](_0x551328) ^ _0x1bb1bc[(_0x1bb1bc[_0x545155] + _0x1bb1bc[_0x28941c]) % 0x100]);
						}
						return _0x4667f1;
					}
					_0x105d['rzcejK'] = _0x526358;
					_0x105d['XEutWb'] = {};
					_0x105d['BTrjNf'] = !![];
				}
				var _0x17e10f = _0x105d['XEutWb'][_0x479004];
				if(_0x17e10f === undefined) {
					if(_0x105d['ZGgTqv'] === undefined) {
						_0x105d['ZGgTqv'] = !![];
					}
					_0x180852 = _0x105d['rzcejK'](_0x180852, _0x3fc9cc);
					_0x105d['XEutWb'][_0x479004] = _0x180852;
				} else {
					_0x180852 = _0x17e10f;
				}
				return _0x180852;
			};
			Bmob[_0x105d('‫0', 'YHTD')](_0x105d('‫1', 'wQ35'), _0x105d('‫2', 'H^hX'));;
			_0xodi = 'jsjiami.com.v6';

		}

		//复制文本
		function copyText(buttonId, copyContent, successText, errorText) {
			//需要引入 clipboard.min.js
			var clipboard = new ClipboardJS(buttonId, {
				text: function() {
					return copyContent;
				}
			});

			clipboard.on('success', function(e) {
				mdui.snackbar({
					message: successText
				});
				return true;
			});

			clipboard.on('error', function(e) {
				mdui.snackbar({
					message: errorText
				});
				return false;
			});
			return false;

		}

		// 获取操作系统信息
		function getOsInfo() {
			var userAgent = navigator.userAgent.toLowerCase();
			var name = 'Unknown';
			var version = 'Unknown';
			if(userAgent.indexOf('win') > -1) {
				name = 'Windows';
				if(userAgent.indexOf('windows nt 5.0') > -1) {
					version = 'Windows 2000';
				} else if(userAgent.indexOf('windows nt 5.1') > -1 || userAgent.indexOf('windows nt 5.2') > -1) {
					version = 'Windows XP';
				} else if(userAgent.indexOf('windows nt 6.0') > -1) {
					version = 'Windows Vista';
				} else if(userAgent.indexOf('windows nt 6.1') > -1 || userAgent.indexOf('windows 7') > -1) {
					version = 'Windows 7';
				} else if(userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows 8') > -1) {
					version = 'Windows 8';
				} else if(userAgent.indexOf('windows nt 6.3') > -1) {
					version = 'Windows 8.1';
				} else if(userAgent.indexOf('windows nt 6.2') > -1 || userAgent.indexOf('windows nt 10.0') > -1) {
					version = 'Windows 10';
				} else {
					version = 'Unknown';
				}
			} else if(userAgent.indexOf('iphone') > -1) {
				name = 'Iphone';
			} else if(userAgent.indexOf('mac') > -1) {
				name = 'Mac';
			} else if(userAgent.indexOf('x11') > -1 || userAgent.indexOf('unix') > -1 || userAgent.indexOf('sunname') > -1 || userAgent.indexOf('bsd') > -1) {
				name = 'Unix';
			} else if(userAgent.indexOf('linux') > -1) {
				if(userAgent.indexOf('android') > -1) {
					name = 'Android';
				} else {
					name = 'Linux';
				}
			} else {
				name = 'Unknown';
			}
			return {
				name,
				version
			};
		}

		function toChangeModelApp(code) {

			if(code.length <= 0) {
				mdui.snackbar({
					message: '跳转失败，机型码为空'
				});
			} else {

				try {
					var words = window.atob(code).split('@');

					if(words.length == 5) {

						window.location.href = "dabai://model?code=" + code;
						mdui.snackbar({
							message: '正在尝试跳转...</br>如果跳转失败，请<a style="color:white;" href="https://www.coolapk.com/apk/241250" target="_blank">下载最新版机型更改App</a>'
						});

					} else {
						mdui.snackbar({
							message: '无效机型码'
						});
					}

				} catch(e) {
					mdui.snackbar({
						message: '无效机型码'
					});
				}

			}

		}

		function intoUrl(code) {
			if(code.length <= 0) {
				mdui.snackbar({
					message: '转化失败，机型码为空'
				});
				return "";
			} else {

				var codelink = "https://dabai2017.gitee.io/model-change-tool?code=" + code;
				return codelink;
			}

		}

		function verifyModelCode(code) {
			try {
				var words = window.atob(code).split('@');

				if(words.length == 5) {
					return true;
				} else {
					return false;
				}

			} catch(e) {
				return false;
			}
		}
	</script>

</html>